package com.bk.controller;

import com.bk.domain.Article;
import com.bk.service.ArticleService;
import com.bk.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Result addArticle(@RequestBody Article article) {
        return articleService.addArticle(article);
    }
    @PostMapping("/draft")
    public Result draft(@RequestBody Article article) {
        return articleService.draft(article);
    }

    @GetMapping
    public Result getAll() {
        return Result.success(articleService.list());
    }

    @GetMapping("{id}")
    public Result getById(@PathVariable String id) {
        return Result.success(articleService.getById(id));
    }

    @PutMapping
    public Result updateArticle(@RequestBody Article article) {
        return articleService.updateArt(article);
    }

    @DeleteMapping("{id}")
    public Result deleteArticle(@PathVariable Integer id) {
        return Result.success(articleService.removeById(id));
    }

    @GetMapping("/list/{authorId}")
    public Result getArticleByAuthorId(@PathVariable Integer authorId) {
        return articleService.getArticleByAuthorId(authorId);
    }

    @GetMapping("/search/{keyword}")
    public Result search(@PathVariable String keyword) {
        return articleService.search(keyword);
    }

}
